package mamikeji.liaowa.widget.clock.data;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Alarm数据库
 * Created by Administrator on 2016/3/4.
 */
public class MyAlarmOpenHelper extends SQLiteOpenHelper {
    private static final int DATABASE_VERSION = 1;
    private static final String DATABASE_NAME = " LIAOWA_AlarmDatabase";
    private static final String TABLE_ALARM = " LIAOWA_AlarmTable";
    private static final String TABLE_QUESTION = " LIAOWA_AlarmQuestion";

    private static final String KEY_id = "id";
    private static final String KEY_usercode = "usercode";
    private static final String KEY_typeName = "typeName";
    private static final String KEY_timeGuid = "timeGuid";
    private static final String KEY_time = "time";
    private static final String KEY_week = "week";
    private static final String KEY_weekCode = "weekCode";
    private static final String KEY_mWakeType = "mWakeType";
    private static final String KEY_mActive = "mActive";
    private static final String KEY_mRing = "mRing";
    private static final String KEY_parentID = "parentID";

    private static final String KEY_QUESTION_ID = "que_id";
    private static final String KEY_QUESTION = "question";
    private static final String KEY_ANSWER = "answer" ;
    private static final String KEY_ALARM_ID = "alarm_id";

    String CREATE_ALARM_TABLE = "CREATE TABLE" + TABLE_ALARM +

            "("
            + KEY_id + " INTEGER PRIMARY KEY,"
            + KEY_usercode + " TEXT,"
            + KEY_typeName + " TEXT,"
            + KEY_timeGuid + " TEXT,"
            + KEY_time + " INTEGER,"
            + KEY_week + " TEXT,"
            + KEY_weekCode + " TEXT,"
            + KEY_mWakeType + " TEXT,"
            + KEY_mActive + " BOOLEAN,"
            + KEY_mRing + " TEXT,"
            + KEY_parentID + " TEXT"+ ")";

    String CREATE_QUESTION_TABLE = "CREATE TABLE" + TABLE_QUESTION+
            "("
            + KEY_QUESTION_ID + " INTEGER PRIMARY KEY,"
            + KEY_QUESTION + " TEXT,"
            + KEY_ANSWER + " TEXT,"
            + KEY_ALARM_ID + " INTEGER"+")";

    public MyAlarmOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_ALARM_TABLE);
        db.execSQL(CREATE_QUESTION_TABLE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        if(oldVersion >= newVersion){
            return;
        }
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_ALARM);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_QUESTION);
        onCreate(db);
    }
}
